//
//  CommentFrame.m
//  EveryDay
//
//  Created by tidoo on 16/4/20.
//  Copyright © 2016年 张广龙. All rights reserved.
//

#import "CommentFrame.h"


@implementation CommentFrame

- (void)setCommentinfo:(CommentInfo *)commentinfo
{
    _commentinfo=commentinfo;
    self.titleiconF=CGRectMake(10, 10, 50, 50);
    
    CGFloat viewX=CGRectGetMaxX(self.titleiconF)+10;
    self.nameF=CGRectMake(viewX, CGRectGetMinY(self.titleiconF), kScreenW-CGRectGetMaxX(self.titleiconF)-60, 20);
    //    self.topF=CGRectMake(kScreenH-70, CGRectGetMinY(self.titleiconF), 60, 20); //置顶
    
    CGFloat commentH=[Global getSizeOfString:commentinfo.topic_context maxWidth: kScreenW-viewX-20 maxHeight:CGFLOAT_MAX withFontSize:14.6].height;
    self.commentF=CGRectMake(CGRectGetMinX(self.nameF), CGRectGetMaxY(self.nameF) + 10, kScreenW-viewX-20, commentH);
    
    CGFloat midlineY=CGRectGetMaxY(self.commentF)+10 ;
    if (commentinfo.image_list.count && !strIsEmpty(commentinfo.image_list[0])) {
        self.commentImageF=CGRectMake(CGRectGetMinX(self.nameF), CGRectGetMaxY(self.commentF) + 10,  kScreenW-viewX-25, (( kScreenW-viewX-20)/3.0 + 10) * ((commentinfo.image_list.count-1)/3+1));
        midlineY=CGRectGetMaxY(self.commentImageF);
    }
    self.dateF=CGRectMake(CGRectGetMinX(self.nameF), midlineY, [Global getSizeOfString:[Global callBackDateTime:commentinfo.add_time] maxWidth:200 maxHeight:20 withFontSize:14.6].width, 20);
    self.deleteF = CGRectMake(CGRectGetMaxX(self.dateF), midlineY, 40, 20);
    self.scanMoreF = CGRectMake(CGRectGetMinX(self.nameF), CGRectGetMaxY(self.commentImageF), 70, 10);
    
    self.zanF=CGRectMake(kScreenW-115, midlineY, 40, 16);
    self.replayF=CGRectMake(kScreenW-70, CGRectGetMinY(self.zanF), 50, 16);
    
    midlineY = midlineY + 20 + 5;
    CGFloat cellheight=midlineY ;
    if (commentinfo.pariseList.count) {
        NSMutableArray *pariseArray = [NSMutableArray array];
        [commentinfo.pariseList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [pariseArray addObject:obj[@"name"]];
        }];
        NSString *zanPeopleStr = [NSString stringWithFormat:@"\U0000e607 %@", [pariseArray componentsJoinedByString:@","]];
        self.triangleimageF = CGRectMake(CGRectGetMinX(self.nameF) + 20, midlineY - 5, 12, 5);
        self.zanPeoPleF = CGRectMake( CGRectGetMinX(self.nameF) + 5, midlineY, kScreenW-CGRectGetMinX(self.nameF)-35, [Global getSizeOfString:zanPeopleStr maxWidth:kScreenW-CGRectGetMinX(self.nameF)-35 maxHeight:CGFLOAT_MAX withFontSize:14.6].height + 5);
        self.zanViewF = CGRectMake( CGRectGetMinX(self.nameF), CGRectGetMinY(self.zanPeoPleF), CGRectGetWidth(self.zanPeoPleF) + 5, CGRectGetHeight(self.zanPeoPleF));
        midlineY=CGRectGetMaxY(self.zanPeoPleF);
        cellheight=midlineY;
    }else{
        self.zanViewF = CGRectZero;
    }
    if (commentinfo.pariseList.count && commentinfo.comment_list.count) {
        self.midlineF=CGRectMake(CGRectGetMinX(self.nameF), midlineY, kScreenW-CGRectGetMinX(self.nameF)-30, 0.5);
    }
    if (commentinfo.comment_list.count) {
        double replayHeight = 0.01;
        for (int i=0; i<commentinfo.comment_list.count; i++) {//回复评论高度
            ReplayInfo *replayinfo=commentinfo.comment_list[i];
            NSString *name=replayinfo.user_name;
            NSString *repName ;
            NSString *content=replayinfo.content;
            NSString *showStr = [NSString stringWithFormat:@"%@ :  %@",name,content];
            if (!strIsEmpty(replayinfo.to_user_name)) {
                repName = replayinfo.to_user_name;
                showStr =  [NSString stringWithFormat:@"%@回复%@:  %@",name,repName,content];
            }
            CGFloat replayH=[Global getSizeOfString:showStr maxWidth:kScreenW-CGRectGetMinX(self.nameF)-30 maxHeight:CGFLOAT_MAX withFontSize:14.6].height+5;
            replayHeight+=(replayH+5);
        }
        cellheight += replayHeight;
        self.replayViewF=CGRectMake(CGRectGetMinX(self.nameF), midlineY, kScreenW-CGRectGetMinX(self.nameF)-30, replayHeight);
        if (!commentinfo.pariseList.count){
            self.triangleimageF = CGRectMake(CGRectGetMinX(self.nameF) + 20, midlineY - 5, 12, 5);
        }
    }
    self.lineF=CGRectMake(0, cellheight, kScreenW, 0.5);
    self.cellheight= cellheight + 10;
    
}

@end
